var tddjs = tddjs || {};

// TMP - until we implement the server API
tddjs.TodoList = function () {
    this.items = [];
};

tddjs.TodoList.prototype = {
    add: function (item, callback) {
        this.items.push({
            text: item,
            done: false,
            id: this.items.length
        });

        if (typeof callback == "function") {
            callback(null, this.items[this.items.length - 1]);
        }
    },

    all: function (callback) {
        jQuery.ajax({
            url: "/todo-items",
            success: function (data, xhr) {
                callback(null, data);
            },
            error: function (xhr) {
                callback({ message: xhr.status + ": " + xhr.responseText });
            }
        });
    },

    completeItem: function (id, callback) {
        this.items[id].done = true;

        if (typeof callback == "function") {
            callback(null, this.items[id]);
        }
    }
};
